function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
};
$(document).ready(function(){
	$('#login-btn').click(function(event){
		event.preventDefault();

		var error = 0;
		$('.log-error').html('');
		if($.trim($('#login-username').val()) == ""){
			$('.log-error').append('<div>Email is required.</div>').fadeIn();
			error = 1;
		}else{
			if(!isValidEmailAddress($.trim($('#login-username').val()))){
				$('.log-error').append('<div>Invalid email format.</div>').fadeIn();
				error = 1;
			}//end if
		}//end if
		if($.trim($('#login-password').val()) == ""){
			$('.log-error').append('<div>Password is required.</div>').fadeIn();
			error = 1;
		}

		if(error == 0){
			var email = $('#login-username').val();
			var password = $('#login-password').val();
			var dataString = 'email='+ email + '&password='+password + '&login_ind=1' ;
			$.ajax({
				url:'home/validate_users',
				type:'POST',
				data: dataString,
				success:function(response){
					if(response == '1'){
						window.location ='profile';

					}else if(response == '0'){
						$('.log-error').hide();
						$('.log-error').html("User Account doesn't exist!").fadeIn();
					}else{
						$('.log-error').hide();
						$('.log-error').html("Please verify your account.").fadeIn();
					}
					return false;
				}
			});
		}//end if
		return false;
	});//end login btn function

});//end document ready

